package com.ml.mall.api.country;

import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.country.CountryAddDto;
import com.ml.mall.bean.res.country.CountryQueryAllRes;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.service.country.CountryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
@Api(tags = "【auth】国家相关接口")
@RestController
@RequestMapping("/common/country")
public class CountryController {
    @Autowired
    private CountryService countryService;

    @ApiOperation(value = "添加国家信息")
    @PostMapping("/new")
//  @RequiresPermissions(PermissionConst.COMMON_COUNTRY_NEW)//未发现调用
    public ApiRestResult addCountry(@RequestBody @Valid CountryAddDto dto){
        int i = countryService.addCountry(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }

    @ApiOperation(value = "查询所有国家信息")
    @PostMapping("/query_all")
//  @RequiresPermissions(PermissionConst.COMMON_COUNTRY_QUERY_ALL)//未发现调用
    public ApiRestResult queryAllCountry(){
        List<CountryQueryAllRes> countryQueryAllRes = countryService.queryAllCountry();
        if (countryQueryAllRes ==null){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok(countryQueryAllRes);
    }

}
